home *** CD-ROM | disk | FTP | other *** search
-
- /* --------------------------------------------------------------
-
- FUNCTION LOCATE_NODE: The steps to locating a node in the list are:
-
- A. Traverse the whole list starting at the root.
-
- B. If the string we are searching for is alphabetically equal to the
- current on in the list return that list entry's address.
-
- C. Else if the new string is less than that in the list the one we
- are searching for isn't in the list. So is we were looking for
- an exact match indicate it wasn't found. For an inexact match
- return the address of the previous node (which must be less than
- the one we are searching for).
-
- D. The match may still be coming so keep looking.
-
- E. We've reached the end of the list so is we were looking for
- an exact match indicate it wasn't found. For an inexact match
- return the address of the previous node (which must be less than
- the one we are searching for).
-
- -------------------------------------------------------------- */
-
- Node *locate_node(const char *pstring, int match)
- {
- Node *ptmp_node = proot_node;
- Node *pold_node = NULL;
- int comp;
-
- /*A*/ while (ptmp_node != NULL) {
- comp = strcmp(pstring, ptmp_node->pstring);
- /*B*/ if (comp == 0) {
- return ptmp_node;
- }
- /*C*/ else if (comp < 0) {
- if (match == EXACT) {
- return NULL;
- }
- else {
- return ptmp_node->pbwd;
- }
- }
- /*D*/ else {
- pold_node = ptmp_node;
- ptmp_node = ptmp_node->pfwd;
- }
- }
-
- /*E*/ if (match == EXACT) {
- return NULL;
- }
- else {
- return pold_node;
- }
- }
-
- /* ----------------------------------------------------------- */
-
-